﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Wpf.Netdisk.Extensions
{
    public static class DictionaryExtensions
    {
        public static List<ByteArrayContent> CreateParamsByteArrayContent(this Dictionary<string, string> dic)
        {
            var list = new List<ByteArrayContent>();
            if (dic == null || dic.Count == 0) return list;
            foreach (var (key, value) in dic)
            {
                var valueBytes = Encoding.UTF8.GetBytes(value);
                var byteArray = new ByteArrayContent(valueBytes);
                byteArray.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name = key
                };
                list.Add(byteArray);
            }

            return list;
        } 
    }
}
